package com.mofang.model;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.mofang.dao.remote.RemoteInteractiveKnowledgeDao;
import com.pactera.framework.exception.NetworkException;
import com.pactera.framework.exception.TimeoutException;
import com.pactera.framework.http.HttpResult;
import com.pactera.framework.model.MapEntity;
import com.pactera.framework.util.Loger;

/**
 * @author Gong 贷款互动
 */
public class StudyModel extends MoFangBaseModel {

	public static final int Id = 1;
	public static final int Intention_area = 10;
	public static final int Intention_total_price = 11;
	public static final int Special_Requirement = 12;
	
	public ArrayList<MapEntity> getKnowledgeCommunicationList(String userId) throws TimeoutException, NetworkException {
		HttpResult httpResult =new RemoteInteractiveKnowledgeDao().getKnowledgeInteractiveList(userId);
		String response = preParseHttpResult(httpResult);
		Loger.d(response);
		ArrayList<MapEntity> mapList=new ArrayList<MapEntity>();
		try {
			JSONObject data=preParseResponse(response);
			if(data!=null){

				JSONArray dataJsonArray = data.getJSONArray("data");
				int dataLength = dataJsonArray.length();
				if (dataLength <= 0) {
					return null;
				}
				for (int i = 0; i < dataLength; i++) {
					JSONObject dataJsonObj = dataJsonArray.getJSONObject(i);
					MapEntity mapEntity = new MapEntity();
					if (dataJsonObj.has("id")) {
						mapEntity.setValue(Id,
								dataJsonObj.getString("id"));
					}
					mapList.add(mapEntity);
				}
			
			}
			//XXX
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return mapList;
	}

}
